package com.hq.bus.controller;


import com.hq.bus.service.CustomerService;
import com.hq.bus.service.RentService;
import com.hq.bus.vo.RentVo;
import com.hq.sys.constat.SysConstant;
import com.hq.sys.util.DataGridView;
import com.hq.sys.util.RandomUtils;
import com.hq.sys.util.ResultObj;
import com.hq.sys.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.Date;
import java.util.Objects;

/**
 * @BelongsPackage: com.hq.bus.controller
 * @Author: jiangjunjie
 * @CreateTime: 2024-12-18  09:47
 * @Description: TODO
 * @Version: 1.8
 */
@RestController
@RequestMapping("rent")
public class RentController {

    @Autowired
    private RentService rentService;

    @Autowired
    private CustomerService customerService;

    /**
     * 加载客户列表返回DataGridView
     * @param rentVo
     * @return
     */
    @RequestMapping("loadAllRent")
    public DataGridView loadAllRent(RentVo rentVo){
        return this.rentService.queryAllRent(rentVo);
    }

    /**
     * 检查身份证号是否存在
     *
     * @param
     * @return
     */
    @RequestMapping("/checkCustomerExit")
    public ResultObj checkCustomerExist(RentVo rentVo) {
       customerService.queryCustomerByIdentity(rentVo.getIdentity());
       return ResultObj.RESET_SUCCESS;

    }

    /**
     * 初始化添加出租单的表单的数据
     *
     * @param rentVo
     * @return
     */
    @RequestMapping("initRentFrom")
    public RentVo initRentFrom(RentVo rentVo) {
        //⽣成出租单号
        rentVo.setRentid(RandomUtils.createRandomStringUseTime(SysConstant.CAR_ORDER_CZ));
        //设置起租时间
        rentVo.setBegindate(new Date());
        //设置操作员
        if (Objects.nonNull(WebUtils.getHttpServletRequest())){
            rentVo.setCreatetime(new Date());
            rentVo.setOpername(WebUtils.getHttpServletRequest().getAttribute("user").toString());
        }else{
            rentVo.setOpername("系统管理员");
        }
        return rentVo;

    }

    //根据时间段查询出租单
   /* @RequestMapping("loadAllRent")
    public DataGridView loadAllRent(RentVo rentVo) {
        Weekend<Rent> weekend = Weekend.of(Rent.class);
        if (Objects.nonNull(rentVo.getStartTime())) {
            weekend.weekendCriteria().andBetween(Rent::getBegindate, rentVo.getStartTime(), rentVo.getEndTime());
            rentVo.setStartTime(null);
        }
        return null;
    }*/
}

